import React, { PureComponent, Fragment } from 'react';
import { connect } from 'dva';
import {
  Spin,
  Row,
  Col,
  Card,
  Form,
  Input,
  Select,
  Icon,
  Button,
  Dropdown,
  Menu,
  InputNumber,
  DatePicker,
  Modal,
  message,
  Badge,
  Divider,
  Steps,
  Radio,
} from 'antd';
import moment from 'moment';
import router from 'umi/router';

import OrderBarChart from './OrderBarChart'; // 柱状图
import OrderTimeLineChart from './OrderTimeLineChart'; // 折线图
import TradeList from './TradeList';
import StandardTable from '@/components/StandardTable';
import PageHeaderWrapper from '@/components/PageHeaderWrapper';

import styles from './Test.less';

const FormItem = Form.Item;
const { Step } = Steps;
const { TextArea } = Input;
const { Option } = Select;
const RadioGroup = Radio.Group;
const getValue = obj =>
  Object.keys(obj)
    .map(key => obj[key])
    .join(',');
const statusMap = ['default', 'processing', 'success', 'error'];

// 弹窗页面1
@Form.create()
class UpdateForm extends PureComponent {
  constructor(props) {
    super(props);
    this.state = {
      currentStep: 0,
      status: 0,
      param: {
        stockId: '',
        orderField: '', // 排序字段
        orderType: 0, // 排序方向
      },
    };
    this.formLayout = {
      labelCol: { span: 7 },
      wrapperCol: { span: 13 },
    };
    this.selectedRows = [];
  }

  /*
    handleAddOrUpdate = currentStep => {
      const {form, handleUpdate} = this.props;
      const {formVals: oldValue} = this.state;
      this.setState({
        status: 0
      });
      form.validateFields((err, fieldsValue) => {
        if (err) return;
        const formVals = {...oldValue, ...fieldsValue};
        this.setState(
          {
            formVals,
          },
          () => {
            handleUpdate(formVals);
          }
        );
      });

    };
    renderAdvancedForm(param = {}) {
      const {
        form: {getFieldDecorator},
      } = this.props;
      return (
        <Form onSubmit={this.handleSearch} layout="inline">
          <Row gutter={{md: 4, lg: 24, xl: 48}}>
            <Col md={4} sm={24}>
              <FormItem label="均值">
                {param.formVals.meanValue}
              </FormItem>
            </Col>

            <Col md={4} sm={24}>
              <FormItem label="最大涨幅 ">
                {param.formVals.maxValue}
              </FormItem>
            </Col>

            <Col md={4} sm={24}>
              <FormItem label="涨的均值">
                {param.formVals.meanValueOfRise}
              </FormItem>
            </Col>

            <Col md={4} sm={24}>
              <FormItem label="涨的中位数">
                {param.formVals.medianValueOfRise}
              </FormItem>
            </Col>

            <Col md={4} sm={24}>
              <FormItem label="胜率">
                {param.formVals.winRate}
              </FormItem>
            </Col>

          </Row>
          <Row gutter={{md: 4, lg: 24, xl: 48}}>

            {/!*          <Col md={8} sm={24}>
              <FormItem label="下个财报时间">
                {param.data2.list.nextEarningsDate}
              </FormItem>
            </Col>*!/}

            <Col md={4} sm={24}>
              <FormItem label="中位数">
                {param.formVals.medianValue}
              </FormItem>
            </Col>

            <Col md={4} sm={24}>
              <FormItem label="最大跌幅">
                {param.formVals.minValue}
              </FormItem>
            </Col>

            <Col md={4} sm={24}>
              <FormItem label="跌的均值">
                {param.formVals.meanValueOfFall}
              </FormItem>
            </Col>

            <Col md={4} sm={24}>
              <FormItem label="跌的中位数">
                {param.formVals.medianValueOfFall}
              </FormItem>
            </Col>

            <Col md={4} sm={24}>
              <FormItem label="市值">
                {param.formVals.marketValue}
              </FormItem>
            </Col>


          </Row>
        </Form>
      );
    }
    //改变每页条数和当前页
    handleStandardTableChange = (pagination, filtersArg, sorter, extra) => {
      const {handleAdd} = this.props;
      const {param, status} = this.state;

      const filters = Object.keys(filtersArg).reduce((obj, key) => {
        const newObj = {...obj};
        newObj[key] = getValue(filtersArg[key]);
        return newObj;
      }, {});


      param.stockId = extra.currentDataSource[0].stockId;
      param.pageNum = 1;
      param.pageSize = 100;

      if (sorter.field) {//排序参数
        param.orderField = `${sorter.field}`;
        if (sorter.order == 'ascend') {
          param.orderType = 2;//升序
        } else if (sorter.order == 'descend') {
          param.orderType = 1;//降序
        } else {
          param.orderType = 0;//不排序
        }
      }
      const params = {
        ...param,
        ...filters,
      };
      handleAdd(params);


    };
    renderFooter = currentStep => {
      const {handleUpdateModalVisible, values} = this.props;
      return [
        <Button key="cancel" onClick={() => handleUpdateModalVisible(false, values)}>
          关闭
        </Button>,
        <Button key="submit" type="primary" onClick={() => this.previewItem()}>
          查看详情
        </Button>,
      ];

    };
    renderContent = (formVals) => {
      const {form} = this.props;
      return (
        <Form onSubmit={this.handleSearch} layout="inline">
          <Row gutter={{md: 4, lg: 12, xl: 24}}>

            <Col md={4} sm={24}>
              <FormItem label="均值">
                {formVals.meanValue}
              </FormItem>
            </Col>

            <Col md={4} sm={24}>
              <FormItem label="最大涨幅 ">
                {formVals.maxValue}
              </FormItem>
            </Col>

            <Col md={4} sm={24}>
              <FormItem label="涨的均值">
                {formVals.meanValueOfRise}
              </FormItem>
            </Col>

            <Col md={4} sm={24}>
              <FormItem label="涨的中位数">
                {formVals.medianValueOfRise}
              </FormItem>
            </Col>

            <Col md={4} sm={24}>
              <FormItem label="胜率">
                {formVals.winRate}
              </FormItem>
            </Col>
          </Row>

          <Row gutter={{md: 4, lg: 12, xl: 24}}>


            <Col md={4} sm={24}>
              <FormItem label="中位数">
                {formVals.medianValue}
              </FormItem>
            </Col>

            <Col md={4} sm={24}>
              <FormItem label="最大跌幅">
                {formVals.minValue}
              </FormItem>
            </Col>

            <Col md={4} sm={24}>
              <FormItem label="跌的均值">
                {formVals.meanValueOfFall}
              </FormItem>
            </Col>

            <Col md={4} sm={24}>
              <FormItem label="跌的中位数">
                {formVals.medianValueOfFall}
              </FormItem>
            </Col>

            <Col md={4} sm={24}>
              <FormItem label="市值">
                {formVals.marketValue}
              </FormItem>
            </Col>


          </Row>

        </Form>
      );
    };
    renderContentList = (formVals) => {
      const newdata = {
        list: formVals != undefined ? formVals.fundEarningDateChangeRateModels : [],
        pagination: {
          current: 1,
          pageSize: 100,
          total: 40
        }
      };
      return (
        <div>
          <div className={styles.tableListForm}>{this.renderAdvancedForm({formVals})}</div>
          <StandardTable
            selectedRows={false}
            loading={false}
            data={newdata}
            columns={this.columns}
            pagination={false}
            onChange={this.handleStandardTableChange}
            rowKey='id'
          />
        </div>

      );
    };
    previewItem() {
      this.setState({
        status: 1
      });
      /!* router.push(`/OrderSystem/Option/TradeList`);*!/
    };
  */

  // 弹窗初始化
  render() {
    const { updateModalVisible, handleUpdateModalVisible, values, titlename } = this.props;
    const { currentStep, formVals } = this.state;
    return (
      <Modal
        width={1080}
        bodyStyle={{ padding: '32px 40px 48px' }}
        destroyOnClose
        title={`${titlename} 历史涨跌幅信息`}
        visible={updateModalVisible}
        footer={null}
        onCancel={() => handleUpdateModalVisible(false, values)}
        /*        footer={this.renderFooter(currentStep)} */
        /*        afterClose={() => handleUpdateModalVisible()} */
        /*        loading={true} */
      >
        {/*        {this.renderContent(textBoxList)} */}
        {/*        {this.state.status==0?this.renderContent(textBoxList):this.renderContentList(textBoxList)} */}
        <TradeList />
      </Modal>
    );
  }
}

// 弹窗页面-折线图
@Form.create()
class IconForm extends PureComponent {
  constructor(props) {
    super(props);
    this.state = {
      currentStep: 0,
      status: 0,
      param: {
        stockId: '',
        orderField: '', // 排序字段
        orderType: 0, // 排序方向
      },
    };
    this.formLayout = {
      labelCol: { span: 7 },
      wrapperCol: { span: 13 },
    };
    this.selectedRows = [];
  }

  // 弹窗初始化
  render() {
    const { IconModalVisible, handleIconModalVisible, values, titlename, instrument } = this.props;
    const { currentStep, formVals } = this.state;
    return (
      <Modal
        width={1080}
        bodyStyle={{ padding: '32px 40px 48px' }}
        destroyOnClose
        title={`${titlename} 折线图`}
        visible={IconModalVisible}
        footer={null}
        onCancel={() => handleIconModalVisible(false, values)}
      >
        <OrderTimeLineChart instrument={instrument} />
      </Modal>
    );
  }
}

// 弹窗页面-柱状图
@Form.create()
class HistogramForm extends PureComponent {
  constructor(props) {
    super(props);
    this.formLayout = {
      labelCol: { span: 7 },
      wrapperCol: { span: 13 },
    };
    this.selectedRows = [];
  }

  // 弹窗初始化
  render() {
    const {
      HistogramModalVisible,
      handleHistogramVisible,
      values,
      titlename,
      instrument,
    } = this.props;
    return (
      <Modal
        width={1280}
        bodyStyle={{ padding: '32px 40px 48px' }}
        destroyOnClose
        title={`${titlename} 概率图`}
        visible={HistogramModalVisible}
        footer={null}
        onCancel={() => handleHistogramVisible(false, values)}
      >
        <OrderBarChart instrument={instrument} />
      </Modal>
    );
  }
}

/* eslint react/no-multi-comp:0 */
@connect(({ rule, loading }) => ({
  rule,
  loading: loading.models.ruleTest,
}))
@Form.create()
class Royalties extends PureComponent {
  state = {
    filterData: [],
    expandForm: false, // 查询菜单栏 是否显示
    listLoading: false,
    formValues: {
      dueDate: null,
      maxEarningsDate: null,
      minBreakEvenMargin: null,
      minEarningsDate: null,
      minMarketValue: null,
      maxMarketValue: null,
      minRoyalty: null,
      minYieldRate: null,
      stockId: null,

      orderType: 0, // 排序方向
      orderField: '', // 排序字段
      pageSize: 10, // 页面大小
      pageNum: 1, // 当前页
    }, // 查询菜单栏   查询参数

    textboxValues: {
      key: '',
      type: 1,
    },
    modalVisible: false,
    updateModalVisible: false,
    IconModalVisible: false,
    titlename: '',
    instrument: '', // 折线图 所需参数
    HistogramModalVisible: false,

    selectedRows: [],

    stepFormValues: {},
    textBoxList: {},
    status: 1, // set
    suggestions: [],
  };

  // 默认加载数据-起始方法
  render() {
    const columns = [
      {
        title: '期权类型',
        dataIndex: 'typeStr',
        width: 80,
        // fixed: 'left'
      },
      /*      {
              title: '',
              dataIndex: 'id',
              render: text => <span>{}</span>,
            }, */

      {
        title: '股票代码',
        dataIndex: 'stockId',
        width: 100,
      },
      {
        title: '执行价格',
        dataIndex: 'strikePrice',

        needTotal: true,
      },
      {
        title: '收盘价',
        dataIndex: 'closePrice',
      },
      {
        title: '权利金',
        dataIndex: 'royalty',
      },
      {
        title: '实际剩余天数',
        dataIndex: 'dueDays',
      },
      {
        title: '到期日',
        dataIndex: 'dueDate',
        filters: this.state.filterData,
      },
      {
        title: '距市场价%',
        dataIndex: 'distanceMarketValue',
      },
      {
        title: '收益率',
        dataIndex: 'yieldRate',
        sorter: true,
      },
      {
        title: '保本幅度%',
        dataIndex: 'breakEvenMargin',
        sorter: true,
      },
      {
        title: '平值收益率',
        dataIndex: 'flatReturnRate',
        sorter: true,
      },
      {
        title: '财报日',
        dataIndex: 'earningsDate',
        sorter: true,
      },
      {
        title: '除权日',
        dataIndex: 'exRightDate',
        sorter: true,
      },
      {
        title: '市值(亿)',
        dataIndex: 'marketValue',
        sorter: true,
      },
      {
        title: 'IV增长率',
        dataIndex: 'impliedVolatilityAvg',
        sorter: true,
      },
      {
        title: '行业',
        dataIndex: 'industry',
      },
      {
        title: '操作',
        // fixed: 'right',
        render: (text, record) => (
          <Fragment>
            <a onClick={() => this.handleUpdateModalVisible(true, record)}>财报历史</a>
            <Divider type="vertical" />
            <a onClick={() => this.handleIconModalVisible(true, record)}>IV</a>

            <Divider type="vertical" />
            <a onClick={() => this.handleHistogramVisible(true, record)}>概率图</a>
          </Fragment>
        ),
      },
    ];
    const {
      rule: { data, filterData },
      loading,
      total,
    } = this.props;
    // this.state.filterData = this.props.rule.filterData.list;

    const {
      selectedRows,
      modalVisible,
      updateModalVisible,
      listLoading,
      titlename,
      IconModalVisible,
      instrument,
      HistogramModalVisible,
    } = this.state;
    const updateMethods = {
      handleUpdateModalVisible: this.handleUpdateModalVisible,
      handleUpdate: this.handleUpdate,
      textBoxList: this.textBoxList,
      handleAdd: this.handleAdd,
    };
    const IconMethods = {
      handleIconModalVisible: this.handleIconModalVisible,
    };
    const HistogramMethods = {
      handleHistogramVisible: this.handleHistogramVisible,
    };
    return (
      <PageHeaderWrapper title="个股权利金收益率统计列表">
        <Card bordered={false}>
          <div className={styles.tableList}>
            <div className={styles.tableListForm}>{this.renderForm()}</div>
            <StandardTable
              selectedRows={selectedRows}
              loading={listLoading}
              data={data}
              columns={columns}
              onChange={this.handleStandardTableChange}
              rowKey="id"
              // scroll={{x: "auto"}}
              bordered
            />
          </div>
        </Card>
        <UpdateForm
          {...updateMethods}
          updateModalVisible={updateModalVisible}
          titlename={titlename}
        />
        <IconForm
          {...IconMethods}
          IconModalVisible={IconModalVisible}
          titlename={titlename}
          instrument={instrument}
        />
        <HistogramForm
          {...HistogramMethods}
          HistogramModalVisible={HistogramModalVisible}
          titlename={titlename}
          instrument={instrument}
        />
      </PageHeaderWrapper>
    );
  }

  // 加载完 之后 再加载 此 方法
  componentDidMount() {
    const { dispatch } = this.props;
    const { formValues } = this.state;
    dispatch({
      type: 'rule/GetRoyaltiesList',
      payload: formValues,
    });

    dispatch({
      type: 'rule/GetFilterList',
    });

    document.body.addEventListener('keyuo', e => {
      if (window.event) {
        e = window.event;
      }
      const code = e.chaarCode || e.keycode;
      if (code === 13) {
        this.handleSearch();
      }
    });
  }

  componentWillMount() {
    const v = localStorage.getItem('antd-pro-authority');
    if (v === null) {
      router.push('/user/login');
      return false;
    }
    const sTemp = v.substring(1, v.length - 1);
    const sArray = sTemp.split(',');
    for (let i = 0; i < sArray.length; i++) {
      if (sArray[i] === '"guest"') {
        router.push('/user/login');
      }
    }
    document.body.removeEventListener('keyup', () => {});
  }

  // 改变每页条数和当前页
  handleStandardTableChange = (pagination, filtersArg, sorter) => {
    const { dispatch } = this.props;
    const { formValues } = this.state;

    const filters = Object.keys(filtersArg).reduce((obj, key) => {
      const newObj = { ...obj };
      newObj[key] = getValue(filtersArg[key]);
      return newObj;
    }, {});

    formValues.pageNum = pagination.current;
    formValues.pageSize = pagination.pageSize;

    if (sorter.field) {
      // 排序参数
      formValues.orderField = `${sorter.field}`;
      if (sorter.order == 'ascend') {
        formValues.orderType = 2; // 升序
      } else if (sorter.order == 'descend') {
        formValues.orderType = 1; // 降序
      } else {
        formValues.orderType = 0; // 不排序
      }
    } else {
      formValues.orderField = '';
      formValues.orderType = 0; // 不排序
    }
    const params = {
      ...formValues,
      ...filters,
    };
    dispatch({
      type: 'rule/GetRoyaltiesList',
      payload: params,
    });
  };

  // 判断 菜单栏 是 缩放显示 还是 全部展示
  renderForm() {
    const { expandForm } = this.state;
    return expandForm ? this.renderAdvancedForm() : this.renderSimpleForm();
  }

  // 菜单栏- 点击展开显示 事件
  renderAdvancedForm() {
    const {
      form: { getFieldDecorator },
    } = this.props;
    return (
      <Form onSubmit={this.handleSearch} layout="inline">
        <Row gutter={{ md: 8, lg: 24, xl: 48 }}>
          <Col md={14} sm={24}>
            <FormItem label="股票代码">
              {getFieldDecorator('stockId')(
                <Select
                  showSearch
                  style={{ width: '100%' }}
                  placeholder="请输入股票代码"
                  onSearch={this.onSearch.bind(this)}
                  /*  onSelect={this.onSelect.bind(this)} */
                >
                  {this.state.suggestions}
                </Select>
              )}
            </FormItem>
          </Col>
        </Row>

        <Row gutter={{ md: 8, lg: 24, xl: 48 }}>
          <Col md={8} sm={24}>
            <FormItem label="最小财报日">
              {getFieldDecorator('minEarningsDate')(
                <DatePicker
                  style={{ width: '100%' }}
                  placeholder="请输入最小财报日"
                  showTime={{ defaultValue: moment('00:00:00', 'HH:mm:ss') }}
                />
              )}
            </FormItem>
          </Col>
          <Col md={8} sm={24}>
            <FormItem label="最大财报日">
              {getFieldDecorator('maxEarningsDate')(
                <DatePicker
                  style={{ width: '100%' }}
                  placeholder="请输入最大财报日"
                  showTime={{ defaultValue: moment('23:59:59', 'HH:mm:ss') }}
                />
              )}
            </FormItem>
          </Col>
        </Row>

        <Row gutter={{ md: 8, lg: 24, xl: 48 }}>
          <Col md={8} sm={24}>
            <FormItem label="最小市值">
              {getFieldDecorator('minMarketValue')(<Input placeholder="请输入" />)}
            </FormItem>
          </Col>
          <Col md={8} sm={24}>
            <FormItem label="最大市值">
              {getFieldDecorator('maxMarketValue')(<Input placeholder="请输入" />)}
            </FormItem>
          </Col>
        </Row>

        <Row gutter={{ md: 8, lg: 24, xl: 48 }}>
          <Col md={8} sm={24}>
            <FormItem label="最小权利金">
              {getFieldDecorator('minRoyalty')(<Input placeholder="请输入" />)}
            </FormItem>
          </Col>
          <Col md={8} sm={24}>
            <FormItem label="最小收益率">
              {getFieldDecorator('minYieldRate')(<Input placeholder="请输入" />)}
            </FormItem>
          </Col>
          <Col md={8} sm={24}>
            <FormItem label="最小保本幅度">
              {getFieldDecorator('minBreakEvenMargin')(<Input placeholder="请输入" />)}
            </FormItem>
          </Col>
        </Row>

        <div style={{ overflow: 'hidden' }}>
          <div style={{ marginBottom: 24 }}>
            <Button type="primary" htmlType="submit">
              查询
            </Button>
            {/*            <Button style={{ marginLeft: 8 }} onClick={this.handleFormReset}>
              重置
            </Button> */}
            <a style={{ marginLeft: 8 }} onClick={this.toggleForm}>
              收起 <Icon type="up" />
            </a>
          </div>
        </div>
      </Form>
    );
  }

  // 菜单栏 默认收缩显示 事件
  renderSimpleForm() {
    const {
      form: { getFieldDecorator },
    } = this.props;
    return (
      <Form onSubmit={this.handleSearch} layout="inline">
        <Row gutter={{ md: 8, lg: 24, xl: 48 }}>
          <Col md={14} sm={24}>
            <FormItem label="股票代码">
              {getFieldDecorator('stockId')(
                <Select
                  showSearch
                  style={{ width: '100%' }}
                  placeholder="请输入股票代码"
                  onSearch={this.onSearch.bind(this)}
                  /*  onSelect={this.onSelect.bind(this)} */
                >
                  {this.state.suggestions}
                </Select>
              )}
            </FormItem>
          </Col>

          {/*          <Col md={6} sm={24}>
            <FormItem label="最小权利金">
              {getFieldDecorator('minRoyalty')(
                <Input placeholder="请输入"/>
              )}
            </FormItem>
          </Col>
          <Col md={6} sm={24}>
            <FormItem label="最小收益率">
              {getFieldDecorator('minYieldRate')(
                <Input placeholder="请输入"/>
              )}
            </FormItem>
          </Col> */}

          <Col md={6} sm={24}>
            <span className={styles.submitButtons}>
              <Button type="primary" htmlType="submit">
                查询
              </Button>
              <Button style={{ marginLeft: 8 }} onClick={this.handleFormReset}>
                重置
              </Button>
              <a style={{ marginLeft: 8 }} onClick={this.toggleForm}>
                展开 <Icon type="down" />
              </a>
            </span>
          </Col>
        </Row>
      </Form>
    );
  }

  // 菜单栏-查询按钮 事件
  handleSearch = e => {
    e.preventDefault();
    const { dispatch, form } = this.props;
    const { formValues } = this.state;

    form.validateFields((err, fieldsValue) => {
      if (err) return;

      const values = {
        ...fieldsValue,
        updatedAt: fieldsValue.updatedAt && fieldsValue.updatedAt.valueOf(),
      };
      if (values.maxEarningsDate != undefined) {
        formValues.maxEarningsDate = new Date(+values.maxEarningsDate + 8 * 3600 * 1000)
          .toISOString()
          .replace(/T/g, ' ')
          .replace(/\.[\d]{3}Z/, '');
      }
      if (values.minBreakEvenMargin != undefined) {
        formValues.minBreakEvenMargin = parseFloat(values.minBreakEvenMargin);
      }
      if (values.minEarningsDate != undefined) {
        formValues.minEarningsDate = new Date(+values.minEarningsDate + 8 * 3600 * 1000)
          .toISOString()
          .replace(/T/g, ' ')
          .replace(/\.[\d]{3}Z/, '');
      }
      if (values.minRoyalty != undefined) {
        formValues.minRoyalty = parseFloat(values.minRoyalty);
      }
      if (values.minYieldRate != undefined) {
        formValues.minYieldRate = parseFloat(values.minYieldRate);
      }

      if (values.minMarketValue != undefined) {
        formValues.minMarketValue = parseFloat(values.minMarketValue);
      }
      if (values.maxMarketValue != undefined) {
        formValues.maxMarketValue = parseFloat(values.maxMarketValue);
      }
      if (values.stockId != undefined) {
        formValues.stockId = values.stockId;
      }
    });
    formValues.pageNum = 1;
    dispatch({
      type: 'rule/GetRoyaltiesList',
      payload: formValues,
    });
  };

  // 菜单栏- 重置按钮 事件
  handleFormReset = () => {
    const { form, dispatch } = this.props;
    const { formValues } = this.state;
    form.resetFields();
    formValues.maxEarningsDate = null;
    formValues.minBreakEvenMargin = null;
    formValues.minEarningsDate = null;
    formValues.minRoyalty = null;
    formValues.minYieldRate = null;
    formValues.maxMarketValue = null;
    formValues.minMarketValue = null;
    formValues.stockId = null;

    dispatch({
      type: 'rule/GetRoyaltiesList',
      payload: formValues,
    });
  };

  // 菜单栏- 展开 关闭 事件
  toggleForm = () => {
    const { expandForm } = this.state;
    this.setState({
      expandForm: !expandForm,
    });
  };

  // 修改弹窗
  handleUpdateModalVisible = (flag, record = {}) => {
    const {
      dispatch,
      rule: { data2 },
    } = this.props;
    const newparam = {
      // 接口调用参数
      stockId: record.stockId,
      orderField: '', // 排序字段
      orderType: 0, // 排序方向
    };
    dispatch({
      type: 'rule/GetEarningDateChangeRateList',
      payload: newparam,
      callback: response => {
        this.setState({
          updateModalVisible: !!flag,
          titlename: record.stockId,
        });
      },
    });
  };

  // IV - 折线图 按钮点击事件
  handleIconModalVisible = (flag, record = {}) => {
    this.setState({
      IconModalVisible: !!flag, // 是否显示参数
      titlename: record.stockId, // 弹窗组件 名称
      instrument: record.instrument, // 传递到 组件的 参数
    });
  };

  // IV - 柱状图 按钮点击事件
  handleHistogramVisible = (flag, record = {}) => {
    this.setState({
      HistogramModalVisible: !!flag, // 是否显示参数
      titlename: record.stockId, // 弹窗组件 名称
      instrument: record.stockId, // 传递到 组件的 参数
    });
  };

  onSearch(value) {
    /*    const {
          rule: {filterData},
        } = this.props; */
    const { textboxValues, textLoading, suggestions } = this.state;
    this.state.textboxValues.key = value;
    const _this = this;
    // this.state.suggestions=[];
    if (value.length > 0) {
      this.props.dispatch({
        type: 'rule/GetTextBoxList',
        payload: textboxValues,
        callback: () => {
          const suggestionsData = [];
          for (let i = 0; i < _this.props.rule.filterData.list.length; i++) {
            suggestionsData.push(
              <Option key={_this.props.rule.filterData.list[i].address}>
                {_this.props.rule.filterData.list[i].value}
              </Option>
            );
          }
          _this.setState({
            suggestions: suggestionsData,
          });
        },
      });
    }
  }

  onSelect(value) {
    const { dispatch, form } = this.props;
    const { formValues, listLoading } = this.state;

    if (this.state.formValues.stockId != undefined) {
      this.setState({
        listLoading: true,
      });
      dispatch({
        type: 'rule/GetEarningDateChangeRateList',
        payload: {
          stockId: value,
        },
        callback: () => {
          this.setState({
            listLoading: false,
          });
        },
      });
    } else {
      message.warning('股票代码不能为空！');
    }
  }
}

export default Royalties;
